package com.hzhk.happyrent.ui.holder.rent;

import android.content.Context;
import android.content.Intent;
import android.view.View;
import android.view.animation.AlphaAnimation;
import android.view.animation.Animation;
import android.view.animation.AnimationSet;
import android.view.animation.LayoutAnimationController;
import android.view.animation.TranslateAnimation;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.LinearLayout;
import android.widget.Toast;

import com.google.gson.Gson;
import com.hzhk.happyrent.Constants;
import com.hzhk.happyrent.R;
import com.hzhk.happyrent.bean.rent.BaseBean;
import com.hzhk.happyrent.bean.rent.TypesModel;
import com.hzhk.happyrent.network.API;
import com.hzhk.happyrent.network.HttpManager;
import com.hzhk.happyrent.network.MyStringResponse;
import com.hzhk.happyrent.ui.activity.rent.ProductListActivity;
import com.hzhk.happyrent.ui.adapter.rent.HomeFunctionAdapter;
import com.hzhk.happyrent.ui.view.MyGridView;
import com.tamic.novate.Throwable;

import java.util.HashMap;
import java.util.Map;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;


public class HomeGridViewHolder {

    @BindView(R.id.rent_type_function)
    MyGridView rentTypeFunction;
    @BindView(R.id.rent_top_open_wait)
    LinearLayout rentTopOpenWait;
    @BindView(R.id.home_choose_second)
    LinearLayout homeChooseSecond;
    @BindView(R.id.shopping_points)
    LinearLayout shoppingPoints;
    @BindView(R.id.home_product_news)
    LinearLayout homeProductNews;

    private HomeFunctionAdapter homeFunctionAdapter;
    private Context context;
    private TypesModel typesModel;

    public HomeGridViewHolder(View convertView, Context context) {
        this.context = context;
        ButterKnife.bind(this, convertView);
        initView();
    }

    public void setAction(BaseBean baseBean) {
        typesModel=(TypesModel) baseBean;
        homeFunctionAdapter.setList(typesModel);
    }


    private void initView() {
        homeFunctionAdapter = new HomeFunctionAdapter(context);
        rentTypeFunction.setAdapter(homeFunctionAdapter);
        rentTypeFunction.setOnItemClickListener(new OnItemClickListener() {

            @Override
            public void onItemClick(AdapterView<?> arg0, View arg1, int position,
                                    long arg3) {
                Intent intent=new Intent(context, ProductListActivity.class);
                intent.putExtra(Constants.SORT_ID,typesModel.getData().getGoodsTypes().get(position).getId());
                intent.putExtra("sort_tit",typesModel.getData().getGoodsTypes().get(position).getSortTit());
                context.startActivity(intent);
            }
        });
    }
    @OnClick({R.id.home_choose_second, R.id.shopping_points, R.id.home_product_news})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.home_choose_second:
                Intent intent=new Intent(context, ProductListActivity.class);
                intent.putExtra(Constants.GOODS_TYPE,Constants.ACTION2);
                intent.putExtra("sort_tit","二手优选");
                context.startActivity(intent);
                break;
            case R.id.shopping_points:
//                Toast.makeText(context,R.string.function_in_development,Toast.LENGTH_SHORT).show();
                Intent intent1=new Intent(context, ProductListActivity.class);
                intent1.putExtra(Constants.SORT_ID,"99");
                intent1.putExtra("sort_tit","智玩商城");
                context.startActivity(intent1);
                break;
            case R.id.home_product_news:
//                Toast.makeText(context,R.string.function_in_development,Toast.LENGTH_SHORT).show();
                Intent intent2=new Intent(context, ProductListActivity.class);
                intent2.putExtra(Constants.ACTION,Constants.ACTION2);
                intent2.putExtra("sort_tit","新品首发");
                context.startActivity(intent2);
                break;
        }

    }


}